package com.sh.rpc.server.tcp;

import com.sh.rpc.server.HttpServer;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.net.NetServer;
import io.vertx.core.parsetools.RecordParser;

/**
 * tcp服务
 * @author SH
 */
public class VertTcpService implements HttpServer {


    @Override
    public void doStart(int port) {
        Vertx vertx = Vertx.vertx();
        NetServer server = vertx.createNetServer();  // 创建NetServer  TCP服务器

        // 处理请求
        server.connectHandler(new TcpServerHandler());

        // 启动服务
        server.listen(port).onComplete(result -> {
            if (result.succeeded()) {
                System.out.println("TCP Server 启动成功  端口为: " + port);
            }else {
                System.err.println("Failed to start TCP Server: " + port);
            }
        });
    }

    public static void main(String[] args) {
        new VertTcpService().doStart(9999);
    }


}
